package com.zj.java8;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public class Test2 {
    private static final Logger logger = LoggerFactory.getLogger(Test2.class);

    private static final Map<String, Consumer<People>> disMap = new HashMap<String, Consumer<People>>() {
        {
            put("sr", (people) -> {
                people.setSrrate("sr");
                people.setSrDetail("sre");
            });
            put("ir", (people) -> {
                people.setIrrate("ir");
                people.setIrDetail("ire");
            });

            put("ar", (people) -> {
                people.setArrate("ar");
                people.setArDetail("are");
            });
        }
    };


    public static void main(String[] args) {
        String type = "ir";
        People p = new People();
        //============================================================
//        Processer.Handler handler = Processer.irProcess.getHandler();
//        handler.handleIndicator(p);
//        System.out.println(p);

        //============================================================
        Indicator.ARhandle aRhandle = new Indicator.ARhandle();
        aRhandle.setDisIndicator(p);
        logger.info(p.toString());

        //============================================================

        Consumer<People> peopleConsumer = disMap.get(type);
        peopleConsumer.accept(p);
        logger.info(p.toString());


    }

    enum Processer {
        irProcess(new Handler<People>() {
            @Override
            public void handleIndicator(People people) {
                people.setIrrate("ir");
                people.setIrDetail("ire");
            }
        }),
        srProcess(new Handler<People>() {
            @Override
            public void handleIndicator(People people) {
                people.setSrrate("sr");
                people.setSrDetail("sre");
            }
        }),
        arProcess(new Handler<People>() {
            @Override
            public void handleIndicator(People people) {
                people.setArrate("ar");
                people.setArDetail("are");
            }
        });
        private Handler handler;

        Processer(Handler handler) {
            this.handler = handler;
        }

        public Handler getHandler() {
            return handler;
        }

        interface Handler<T> {
            void handleIndicator(T t);
        }

    }


    interface Indicator<T> {
        void setDisIndicator(T t);

        class IRhandle implements Indicator<People> {

            @Override
            public void setDisIndicator(People people) {
                people.setIrrate("ir");
                people.setIrDetail("ire");
            }
        }

        class SRhandle implements Indicator<People> {

            @Override
            public void setDisIndicator(People people) {
                people.setSrrate("sr");
                people.setSrDetail("sre");
            }
        }

        class ARhandle implements Indicator<People> {

            @Override
            public void setDisIndicator(People people) {
                people.setArrate("ar");
                people.setArDetail("are");
            }
        }
    }


    static class People {
        String irrate;
        String srrate;
        String arrate;

        String irDetail;
        String srDetail;
        String arDetail;

        public String getIrrate() {
            return irrate;
        }

        public void setIrrate(String irrate) {
            this.irrate = irrate;
        }

        public String getSrrate() {
            return srrate;
        }

        public void setSrrate(String srrate) {
            this.srrate = srrate;
        }

        public String getArrate() {
            return arrate;
        }

        public void setArrate(String arrate) {
            this.arrate = arrate;
        }

        public String getIrDetail() {
            return irDetail;
        }

        public void setIrDetail(String irDetail) {
            this.irDetail = irDetail;
        }

        public String getSrDetail() {
            return srDetail;
        }

        public void setSrDetail(String srDetail) {
            this.srDetail = srDetail;
        }

        public String getArDetail() {
            return arDetail;
        }

        public void setArDetail(String arDetail) {
            this.arDetail = arDetail;
        }

        @Override
        public String toString() {
            return "People{" +
                    "irrate='" + irrate + '\'' +
                    ", srrate='" + srrate + '\'' +
                    ", arrate='" + arrate + '\'' +
                    ", irDetail='" + irDetail + '\'' +
                    ", srDetail='" + srDetail + '\'' +
                    ", arDetail='" + arDetail + '\'' +
                    '}';
        }
    }
}
